package com.bridge.bridge_wd.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bridge.bridge_wd.R;
import com.bridge.bridge_wd.bean.CityEntity;

import androidx.recyclerview.widget.RecyclerView;
import me.yokeyword.indexablerv.IndexableAdapter;

/**
 * @ClassName CityAdapter
 * @Description TODO消息
 * @Author xushufeng
 * @CreateDate 2021/4/15 0015 21:45
 * @Version 1.0
 * @UpdateDate 2021/4/15 0015 21:45
 * @UpdateRemark 更新说明
 */
public class CityAdapter extends IndexableAdapter<CityEntity> {
    private LayoutInflater mInflater;
    Context context;

    public CityAdapter(Context context) {
        this.context = context;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateTitleViewHolder(ViewGroup parent) {
        View view = mInflater.inflate(R.layout.recycler_view_item_city_title, parent, false);
        return new IndexVH(view);
    }

    @Override
    public RecyclerView.ViewHolder onCreateContentViewHolder(ViewGroup parent) {
        View view = mInflater.inflate(R.layout.recycler_view_item_city, parent, false);
        return new ContentVH(view);
    }

    @Override
    public void onBindTitleViewHolder(RecyclerView.ViewHolder holder, String indexTitle) {
        IndexVH vh = (IndexVH) holder;
        vh.tv.setText(indexTitle);
    }

    @Override
    public void onBindContentViewHolder(RecyclerView.ViewHolder holder, CityEntity entity) {
        ContentVH vh = (ContentVH) holder;
        vh.tv.setText(entity.getFieldIndexBy());

        if (entity.isChecked()) {
            vh.image.setVisibility(View.VISIBLE);
        } else {
            vh.image.setVisibility(View.GONE);
        }


    }

    private class IndexVH extends RecyclerView.ViewHolder {
        TextView tv;

        public IndexVH(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.tv_item);
        }
    }

    private class ContentVH extends RecyclerView.ViewHolder {
        TextView tv;
        ImageView image, head_image;

        public ContentVH(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.tv_name);
            head_image = (ImageView) itemView.findViewById(R.id.head_image);
            image = (ImageView) itemView.findViewById(R.id.image);
        }
    }
}